<template>
    <div class="global-setting-cdkey-page">
        <el-card shadow="never" class="filter" v-loading="loading">
            <el-switch
                @change="onClick"
                v-model="isOpen"
                active-text="兑换码入口开启"
                inactive-text="兑换码入口关闭">
            </el-switch>
        </el-card>
    </div>
</template>

<script>

export default {
    components: {
    },
    data() {
        return {
            loading: false,
            isOpen: false,
        };
    },
    methods: {
        fetchData() {
            this.loading = true;
            API.get('setting/exchange').then((res) => {
                this.isOpen = res;
            }).finally(() => {
                this.loading = false;
            });
        },
        onClick() {
            this.loading = true;
            API.post(`setting/exchange/${this.isOpen}`).finally(() => {
                this.loading = false;
            });
        },
    },
    mounted() {
        this.fetchData();
    },
};
</script>

<style lang="scss">
.global-setting-cdkey-page {
}
</style>
